import { useCallback } from 'react';
import { BackHandler } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';


export function useBlockBackHandler(enabled: boolean = true) {
    useFocusEffect(
        useCallback(() => {
            if (!enabled) return;

            const onBackPress = () => true; // 阻止返回
            BackHandler.addEventListener('hardwareBackPress', onBackPress);

            return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress);
        }, [enabled])
    );
}